﻿//===============================================================================
// La Pomme d'Or Krystal Application
// Windows Presentation Foundation Composite Application 
//===============================================================================
// Copyright (c) Jérôme Piquot.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;
using System.Collections.Generic;

namespace PJ.Data
{
    /// <summary>
    /// Saves and retreive <see cref="IObjectData"/> instance to/from cache
    /// </summary>
    /// <remarks>
    /// The object will be cached using <see cref="IObjectData"/> GlobalID property as cache key. So the <see cref="IObjectData"/> GlobalID property must be unique in the application.
    /// </remarks>
    /// <example>
    /// Add/Find
    /// <code>
    ///     IObjectData data = MyService.GetObject();
    ///     IObjectDataCache cache = CacheFactory.GetCache();
    ///     
    ///     cache.Add(data);
    ///     IObjectData cacheData = cache.Find(data.GlobalID);
    /// </code>
    /// </example>
    public interface IObjectDataCache
    {
        /// <summary>
        /// Finds the <see cref="IObjectData"/> instance in the cache.
        /// </summary>
        /// <param name="globalId">Object global unique identifier</param>
        /// <returns>A <see cref="IObjectData"/>instance object in the cache having GlobalID equal to <paramref name="globalId"/> if found or returns <see langword="null" /></returns>
        /// <exception cref="ArgumentNullException">If the passed <paramref name="globalId"/> is <see langword="null" /> or empty.</exception>
        IObjectData Find(string globalId);

        /// <summary>
        /// Adds the <see cref="IObjectData"/> instance to the cache.
        /// </summary>
        /// <param name="instance"><see cref="IObjectData"/> instance to add to the cache</param>
        /// <returns><paramref name="instance"/> value<see langword="null" /></returns>
        /// <exception cref="ArgumentNullException">If the passed <paramref name="instance"/> is <see langword="null" />.</exception>
        /// <exception cref="ArgumentException">If the passed <paramref name="instance"/> GlobalID or one of the child class key properties (Id for <see cref="IEntityData"/>, Name for <see cref="IItemData"/>, etc) are <see langword="null" /> or empty.</exception>
        IObjectData Add(IObjectData instance);

    }

    /// <summary>
    /// Saves and retreive <see cref="IObjectData"/> instance to/from cache
    /// </summary>
    /// <remarks>
    /// The object will be cached using <see cref="IObjectData"/> GlobalID property as cache key. So the <see cref="IObjectData"/> GlobalID property must be unique in the application.
    /// </remarks>
    /// <example>
    /// Add/Find
    /// <code>
    ///     IObjectData data = MyService.GetObject();
    ///     IObjectDataCache cache = CacheFactory.GetCache();
    ///     
    ///     cache.Add(data);
    ///     IObjectData cacheData = cache.Find(data.GlobalID);
    /// </code>
    /// </example>
    /// <typeparam name="TIObjectData"><see cref="IObjectData">Object</see> data concrete class type to cache.</typeparam>
    public interface IObjectDataCache<TIObjectData> : IObjectDataCache
        where TIObjectData : IObjectData
    {
        /// <summary>
        /// Finds the <see cref="IObjectData"/> instance in the cache.
        /// </summary>
        /// <param name="globalId">Object global unique identifier</param>
        /// <returns>A <see cref="IObjectData"/>instance object in the cache having GlobalID equal to <paramref name="globalId"/> if found or returns <see langword="null" /></returns>
        /// <exception cref="ArgumentNullException">If the passed <paramref name="globalId"/> is <see langword="null" /> or empty.</exception>
        new TIObjectData Find(string globalId);

        /// <summary>
        /// Get a collection of objects from the cache
        /// </summary>
        /// <param name="globalIds">List of ids of the objects to find</param>
        /// <param name="notFound">List of ids of the objects not found in cache</param>
        /// <returns>Dictionary of items found in cache</returns>
        /// <exception cref="ArgumentNullException">If the passed <paramref name="globalId"/> is <see langword="null" /> or empty.</exception>
        Dictionary<string, TIObjectData> Find(string[] globalIds, out string[] notFound);

        /// <summary>
        /// Adds the <see cref="IObjectData"/> instance to the cache.
        /// </summary>
        /// <param name="instance">Instance to add to the cache</param>
        /// <returns><paramref name="instance"/> value<see langword="null" /></returns>
        /// <exception cref="ArgumentNullException">If the passed <paramref name="instance"/> is <see langword="null" />.</exception>
        /// <exception cref="ArgumentException">If the passed <paramref name="instance"/> GlobalID or one of the child class key properties (Id for <see cref="IEntityData"/>, Name for <see cref="IItemData"/>, etc) are <see langword="null" /> or empty.</exception>
        TIObjectData Add(TIObjectData instance);


    }
}
